-
Couldn't load subscription status.
- Fork 713
feat: Improve consensus test ergonomics with snapshot testing #6555
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Improve consensus test ergonomics with snapshot testing #6555
Conversation
33d7113
Codecov Report❌ Patch coverage is
❌ Your project status has failed because the head coverage (65.83%) is below the target coverage (80.00%). You can increase the head coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## develop #6555 +/- ##
============================================
- Coverage 79.88% 65.83% -14.05%
============================================
Files 568 568
Lines 347203 347125 -78
============================================
- Hits 277377 228547 -48830
- Misses 69826 118578 +48752
... and 345 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
|
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Description
This PR is about simplifying the process of writing and updating our consensus tests.
the current drill: write a test, run it, see it fail, extract the data and then manually recreate the ExpectedResult struct from the terminal back into your code. It's easy to mess up.
This change introduces snapshot testing using a crate called
insta.Long story short: with this, we don't have to write the
ExpectedResultby hand!So, how does it work
Instead of stuffing the
ExpectedResultinto our test files,instasaves it automatically into a separate.snapfile (or inline, I have an example). These new files live in asnapshots/directory and we check them into Git. They become the "source of truth" for what the output should be.Pros:
instagenerate the correct output for you.git diffon the.snapfile will show exactly what changed in the output. Reviewing consensus-breaking changes should be easier.How do I use this?
Writing a new test:
ConsensusTestVectorlike before, but just... don't add anexpected_result.let result = ConsensusTest::new(...).run();insta::assert_ron_snapshot!(result);cargo insta reviewto create the snapshot for you:.snapfile along with your code.Updating a test after you broke something (on purpose!):
cargo test. It'll fail, andinstawill print a beautiful diff showing you exactly what's different.cargo insta reviewagain.instawill automatically update the snapshot file for you.Applicable issues
Additional info (benefits, drawbacks, caveats)
Checklist
docs/rpc/openapi.yamlandrpc-endpoints.mdfor v2 endpoints,event-dispatcher.mdfor new events)clarity-benchmarkingrepobitcoin-tests.yml